home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / MAIL / ALIAS.C < prev    next >
C/C++ Source or Header  |  1993-07-20  |  17KB  |  446 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    a l i a s . c                                                   */
  3. /*                                                                    */
  4. /*    Smart routing and alias routines for UUPC/extend mail           */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*                                                                    */
  14. /*    Additional code                                                 */
  15. /*       Copyright (c) Richard H. Lamb 1985, 1986, 1987               */
  16. /*       Changes Copyright (c) Stuart Lynne 1987                      */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*                          RCS Information                           */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. /*
  24.  *    $Id: alias.c 1.6 1993/07/21 01:19:16 ahd Exp $
  25.  *
  26.  *    Revision history:
  27.  *    $Log: alias.c $
  28.  * Revision 1.6  1993/07/21  01:19:16  ahd
  29.  * Incr elements after filling info from passwd, not before!
  30.  *
  31.  * Revision 1.5  1993/07/19  02:52:11  ahd
  32.  * Don't load alias for empty names
  33.  *
  34.  * Revision 1.4  1993/05/06  03:41:48  ahd
  35.  * Use expand_path to get reasonable correct drive for aliases file
  36.  *
  37.  * Revision 1.3  1993/04/11  00:33:05  ahd
  38.  * Global edits for year, TEXT, etc.
  39.  *
  40.  * Revision 1.2  1992/11/22  21:06:14  ahd
  41.  * Use strpool for memory allocation
  42.  *
  43.  *    02 Oct 89   Alter large strings/structures to use
  44.  *                malloc()/free()                              ahd
  45.  *    08 Feb 90   Correct failure of ExtractAddress to return
  46.  *                non-names                                    ahd
  47.  *    18 Mar 90   Move checkname() and associated routines into
  48.  *                hostable.c                                   ahd
  49.  *    22 Apr 90   Modify user_at_node to correctly handle .UUCP
  50.  *                alias on local host.                         ahd
  51.  *
  52.  */
  53.  
  54. #include <ctype.h>
  55. #include <stdio.h>
  56. #include <string.h>
  57. #include <stdlib.h>
  58. #include <sys/types.h>
  59.  
  60. #ifndef __TURBOC__
  61. #include <search.h>
  62. #endif
  63.  
  64. #include "lib.h"
  65. #include "hostable.h"
  66. #include "security.h"
  67. #include "usertabl.h"
  68. #include "hlib.h"
  69. #include "alias.h"
  70. #include "address.h"
  71. #include "expath.h"
  72.  
  73. static size_t AliasCount = 0;
  74.  
  75. static struct AliasTable *alias = NULL;
  76.  
  77. int nickcmp( const void *a, const void *b );
  78.  
  79. static size_t LoadAliases( void ) ;
  80.  
  81. currentfile();
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /*    I n i t R o u t e r                                             */
  85. /*                                                                    */
  86. /*    Verify, initialize the global routing data                      */
  87. /*--------------------------------------------------------------------*/
  88.  
  89. boolean InitRouter()
  90. {
  91.    boolean success = TRUE;       /* Assume the input data is good       */
  92.    struct HostTable *Hptr;
  93.  
  94. /*--------------------------------------------------------------------*/
  95. /*          Verify that the user gave us a good name server           */
  96. /*--------------------------------------------------------------------*/
  97.  
  98.    Hptr = checkreal(E_mailserv);
  99.    if (Hptr == BADHOST)
  100.    {
  101.       printmsg(0,"mail server '%s' must be listed in SYSTEMS file",
  102.          E_mailserv);
  103.       success = FALSE;
  104.    }
  105.    else if (Hptr->hstatus == localhost)  /* local system?     */
  106.    {
  107.       printmsg(0,"'%s' is name of this host and cannot be mail server",
  108.             E_mailserv);
  109.       success = FALSE;
  110.    }
  111.  
  112. /*--------------------------------------------------------------------*/
  113. /*                          Return to caller                          */
  114. /*--------------------------------------------------------------------*/
  115.  
  116.    return success;
  117. } /* InitRouter */
  118.  
  119. /*--------------------------------------------------------------------*/
  120. /*    E x t r a c t N a m e                                           */
  121. /*                                                                    */
  122. /*    Returns full name of user, and returns address if name          */
  123. /*    is not available.                                               */
  124. /*--------------------------------------------------------------------*/
  125.  
  126. void ExtractName(char *result, char *column)
  127. {
  128.       static int recursion = 0;
  129.  
  130.       recursion++;
  131.  
  132.       printmsg((recursion > 2) ? 1:8,
  133.             "ExtractName: Getting name from '%s'",column);
  134.  
  135.       ExtractAddress(result, column, TRUE);  /* Get the full name    */
  136.       if (!strlen(result))       /* Did we get the name?             */
  137.       {                          /* No --> Get the e-mail address    */
  138.          char addr[MAXADDR];
  139.          char path[MAXADDR];
  140.          char node[MAXADDR];
  141.          char *fullname;
  142.  
  143.          ExtractAddress(addr,column, FALSE);
  144.          user_at_node(addr,path,node,result);
  145.                                  /* Reduce address to basics */
  146.          fullname = AliasByAddr(node,result);
  147.          if (fullname == NULL)
  148.          {
  149.             strcat(result,"@");
  150.             strcat(result,node);
  151.          }
  152.          else
  153.             strcpy(result,fullname);
  154.       }
  155.  
  156.       printmsg((recursion > 2) ? 1: 8,"ExtractName: name is '%s'",result);
  157.  
  158.       recursion--;
  159.  
  160.       return;
  161. }  /*ExtractName*/
  162.  
  163. /*--------------------------------------------------------------------*/
  164. /*    B u i l d A d d r e s s                                         */
  165. /*                                                                    */
  166. /*    Builds a standard address format, with aliasing as              */
  167. /*    required.                                                       */
  168. /*--------------------------------------------------------------------*/
  169.  
  170. void BuildAddress(char *result, const char *input)
  171. {
  172.    char addr[MAXADDR];
  173.    char name[MAXADDR];
  174.    char user[MAXADDR];
  175.    char path[MAXADDR];
  176.    char node[MAXADDR];
  177.    char *fulladdr;
  178.  
  179. /*--------------------------------------------------------------------*/
  180. /*   It must be a real address, possibly with a name attached; get    */
  181. /*   the address portion, break the address into user and node, and   */
  182. /*   then see if we know the person by address                        */
  183. /*--------------------------------------------------------------------*/
  184.  
  185.       ExtractAddress(addr,input,FALSE);   /* Get user e-mail addr    */
  186.       user_at_node(addr,path,node,user);  /* Break address down      */
  187.  
  188.       fulladdr = AliasByAddr(node,user);  /* Alias for the address?  */
  189.       if (fulladdr != NULL)            /* Yes --> Use it             */
  190.       {
  191.          strcpy(result,fulladdr);
  192.          return;
  193.       } /* if */
  194.  
  195. /*--------------------------------------------------------------------*/
  196. /*   We don't know the address yet; get the name the user provided,   */
  197. /*   and then normalize the address                                   */
  198. /*--------------------------------------------------------------------*/
  199.  
  200.       ExtractAddress(name,input,TRUE);    /* Also get their name     */
  201.  
  202.       if (strlen(name))             /* Did we find a name for user?  */
  203.       {                             /* Yes --> Return it             */
  204.          char *s = strchr(node, '.');
  205.          if ((s == NULL) || equalni( s, ".UUCP", 5))
  206.                                     /* Simple name or UUCP domain?   */
  207.          {                          /* Yes--> Use original address   */
  208.             size_t pathlen = strlen(path);/* Save len of orig path   */
  209.             if ((p